var express = require('express');
var app = express();
var path = require('path');
//var cookieParser = require('cookie-parser');
var session = require('express-session');
var bodyParser = require('body-parser');
var multer = require('multer');
var flash = require('connect-flash');
var settings = require('./settings');
var routes = require('./routes/index');
var db = require('./tools/db');
var log4js = require('./tools/log4js');
//日志模块
log4js.use(app, 'info');
//视图模板
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//解析json formdata
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: true
}));
app.use(multer());
//cookie session设置
//app.use(cookieParser(settings.app.secret));
app.use(session({
	secret: settings.app.secret,
	key: settings.app.name,
	resave: true,
	saveUninitialized: false,
	cookie: {
		maxAge: 60000
	}
}));
//flash request
app.use(flash());
//静态目录
app.use('/static', express.static(path.join(__dirname, 'public')));

//路由
routes(app);

app.listen(settings.app.port, function() {
	console.log('Express server listening on port ' + settings.app.port);
});